#!/bin/sh
# PCP QA Test No. 479
# coverage for libpcp/logmeta.c
#
# Copyright (c) 2011 Ken McDonell.  All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

status=0	# success is the default!
mkdir $tmp
trap "rm -rf $tmp; exit \$status" 0 1 2 3 15

_filter()
{
    sed \
	-e '/^__pmLoadTimeval:/d' \
	-e '/^inst\[/d' \
	-e '/^auxconnect.c:/d' \
	-e "s;$tmp;TMP;g" \
	-e '/addindom( /s/alloc=0x[0-9a-f][0-9a-f]*)/alloc=0x0)/' \
	-e '/addindom( /s/[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\.[0-9][0-9]*[0-9]/TIMESTAMP/' \
	-e '/__pmLogSearchInDom( /s/[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\.[0-9][0-9]*[0-9]/TIMESTAMP/' \
	-e '/^__pmLogLoadMeta(/s/acp=0x[0-9a-f][0-9a-f]* /acp=ADDR) /' \
	-e '/^logFree/{
s/hcp=0x[0-9a-f][0-9a-f]* /hcp=ADDR /
s/next=0x0 /next=(nil) /
s/next=0x[0-9a-f][0-9a-f]* /next=ADDR /
}' \
    # end
}

_filter2()
{
    _filter_pmie_log \
    | sed -e '/Info: evaluator exiting/d' \
    | _filter
}

pmlogcp archives/bozo.client_v2 $tmp
# pmlogcp does not like bad archives
#
cp badarchives/bozo.client_v2.* $tmp
mv $tmp/bozo.client_v2.meta $tmp/bozo.client_v2.save

# real QA test starts here
for bad in $tmp/bozo.client_v2.meta.bad.*
do
    echo
    echo "=== bad #`echo $bad | sed -e 's/.*\.bad\.//'` ==="
    cp $bad $tmp/bozo.client_v2.meta
    pmdumplog -z -dilmst -Dlogmeta,desperate $tmp/bozo.client_v2 2>&1 \
    | _filter
done

for size in 100 132 136 160 164 407 440 512
do
    echo
    echo "=== size $size ==="
    dd if=$tmp/bozo.client_v2.save bs=1 count=$size of=$tmp/bozo.client_v2.meta >/dev/null 2>&1
    pmdumplog -z -dilmst -Dlogmeta,desperate $tmp/bozo.client_v2 2>&1 \
    | _filter
done

echo
echo "torture_indom ... silence is golden"
src/torture_indom -a archives/ace_v2 disk.dev.total

echo
echo "pmie archive meta data exercises ..."
echo 'some_inst disk.dev.total > 0 -> print "active disks:" " %i"' \
| pmie -z -t 2sec -a archives/ace_v2 2>&1 \
| _filter2
echo
echo 'some_inst disk.dev.total #dks1d1 #dks1d7 > 0 -> print "active disks: " "%i"' \
| pmie -Dlogmeta,desperate -z -t 2sec -a archives/ace_v2 2>&1 \
| _filter2

echo
echo "pmval archive meta data exercises ..."
pmval -z -t 5sec -Dlogmeta,desperate -a archives/ac15 kernel.all.load 2>&1 | _filter
echo
pmval -z -t 5sec -Dlogmeta,desperate -a archives/ac15 -i '"15 minute","5","1 minute"' kernel.all.load 2>&1 | _filter

echo
echo "torture ..."
src/torture_logmeta -Dlogmeta,desperate archives/ac15 60 2 123 2>&1 \
| tee -a $seq_full \
| _filter

# success, all done
exit
